package com.example.home.controller;

import com.example.home.Dao.AdminRepository;
import com.example.home.Entities.Admin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("admins")
public class AdminController {

    @Autowired
    AdminRepository adminRepository;

    @GetMapping("/new")
    public String outAdminForm(Model model){
        Admin admin = new Admin();
        model.addAttribute("admin",admin);
        return "admin/Admin";
    }

    @PostMapping("/save")
    public String CreateStudent(Model model, Admin admin){

        //处理保存数据库的行为
       adminRepository.save(admin);
        //使用定位防止重复提交
        return "redirect:/admins/new";

    }


}
